#include "gtest/gtest.h"
#include "Text.h"
#include "mock/AllocatorMock.h"


class TextTest : public ::testing::Test {
public:
	TextTest() : testStr("ala ma kota") {
		EXPECT_CALL(a, alloc(11)).
			Times(1).
			WillOnce(Return(buf));
		t = new Text(testStr, a);
	}
protected:
	AllocatorMock a;	
	char buf[11];
	char* testStr;
	Text* t;

	virtual void SetUp() {
	}
};

TEST_F(TextTest, cstrInit){
	for(int i = 0; ;++i){
		if(0 == testStr[i])
			break;
		EXPECT_EQ(buf[i], testStr[i]);
	}
}
TEST_F(TextTest, copyConstructor){
	char buf2[11];
	EXPECT_CALL(a, alloc(11)).
		Times(1).
		WillOnce(Return(buf2));
	Text t2(*t);

	for(int i = 0; ;++i){
		if(0 == testStr[i])
			break;
		EXPECT_EQ(buf2[i], testStr[i]);
	}
}
TEST_F(TextTest, assigmentOperator){
	char buf2[11];
	Text t2(a);

	EXPECT_CALL(a, alloc(11)).
		Times(1).
		WillOnce(Return(buf2));
	t2 = *t;

	for(int i = 0; ;++i){
		if(0 == testStr[i])
			break;
		EXPECT_EQ(buf2[i], testStr[i]);
	}
}
TEST_F(TextTest, compOperator){
	EXPECT_EQ("ala ma kota" == *t, true);
	EXPECT_EQ("ala ma zebre" == *t, false);
	EXPECT_EQ("ala ma koty" == *t, false);

	EXPECT_EQ(*t == "ala ma kota", true);
	EXPECT_EQ(*t == "ala ma zebre", false);
	EXPECT_EQ(*t == "ala ma koty", false);
}
